
<!DOCTYPE html>

<html lang="en">
  <head>
    <meta charset="utf-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>第五章 Excel函数-文本函数 &#8212; free-excel</title>
<script>
  document.documentElement.dataset.mode = localStorage.getItem("mode") || "";
  document.documentElement.dataset.theme = localStorage.getItem("theme") || "light"
</script>

  <!-- Loaded before other Sphinx assets -->
  <link href="../_static/styles/theme.css?digest=92025949c220c2e29695" rel="stylesheet">
<link href="../_static/styles/pydata-sphinx-theme.css?digest=92025949c220c2e29695" rel="stylesheet">


  <link rel="stylesheet"
    href="../_static/vendor/fontawesome/5.13.0/css/all.min.css">
  <link rel="preload" as="font" type="font/woff2" crossorigin
    href="../_static/vendor/fontawesome/5.13.0/webfonts/fa-solid-900.woff2">
  <link rel="preload" as="font" type="font/woff2" crossorigin
    href="../_static/vendor/fontawesome/5.13.0/webfonts/fa-brands-400.woff2">

    <link rel="stylesheet" type="text/css" href="../_static/pygments.css" />
    <link rel="stylesheet" type="text/css" href="../_static/css/s4defs-roles.css" />

  <!-- Pre-loaded scripts that we'll load fully later -->
  <link rel="preload" as="script" href="../_static/scripts/pydata-sphinx-theme.js?digest=92025949c220c2e29695">

    <script data-url_root="../" id="documentation_options" src="../_static/documentation_options.js"></script>
    <script src="../_static/jquery.js"></script>
    <script src="../_static/underscore.js"></script>
    <script src="../_static/_sphinx_javascript_frameworks_compat.js"></script>
    <script src="../_static/doctools.js"></script>
    <script src="../_static/sphinx_highlight.js"></script>
    <link rel="shortcut icon" href="../_static/logo.ico"/>
    <link rel="index" title="Index" href="../genindex.html" />
    <link rel="search" title="Search" href="../search.html" />
    <link rel="next" title="第六章 Excel函数-查找函数" href="chap6.html" />
    <link rel="prev" title="第四章 Excel函数-逻辑判断" href="chap4.html" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<meta name="docsearch:language" content="en">
  </head>
  
  
  <body data-spy="scroll" data-target="#bd-toc-nav" data-offset="180" data-default-mode="">
    <div class="bd-header-announcement container-fluid" id="banner">
      

    </div>

    
    <nav class="bd-header navbar navbar-light navbar-expand-lg bg-light fixed-top bd-navbar" id="navbar-main"><div class="bd-header__inner container-xl">

  <div id="navbar-start">
    
    
  


<a class="navbar-brand logo" href="../index.html">
  
  
  
  
    <img src="../_static/logo.svg" class="logo__image only-light" alt="Logo image">
    <img src="../_static/logo.svg" class="logo__image only-dark" alt="Logo image">
  
  
</a>
    
  </div>

  <button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbar-collapsible" aria-controls="navbar-collapsible" aria-expanded="false" aria-label="Toggle navigation">
    <span class="fas fa-bars"></span>
  </button>

  
  <div id="navbar-collapsible" class="col-lg-9 collapse navbar-collapse">
    <div id="navbar-center" class="mr-auto">
      
      <div class="navbar-center-item">
        <ul id="navbar-main-elements" class="navbar-nav">
    <li class="toctree-l1 nav-item">
 <a class="reference internal nav-link" href="../%E4%B8%BB%E9%A1%B5.html">
  主页
 </a>
</li>

<li class="toctree-l1 current active nav-item">
 <a class="reference internal nav-link" href="index.html">
  教程
 </a>
</li>

<li class="toctree-l1 nav-item">
 <a class="reference internal nav-link" href="../%E4%BD%9C%E8%80%85.html">
  作者
 </a>
</li>

<li class="toctree-l1 nav-item">
 <a class="reference internal nav-link" href="../Datawhale.html">
  Datawhale
 </a>
</li>

<li class="toctree-l1 nav-item">
 <a class="reference internal nav-link" href="../%E7%BB%83%E4%B9%A0%E9%A2%98%E5%8F%82%E8%80%83%E6%93%8D%E4%BD%9C.html">
  练习题参考操作
 </a>
</li>

    
</ul>
      </div>
      
    </div>

    <div id="navbar-end">
      
      <div class="navbar-end-item">
        <span id="theme-switch" class="btn btn-sm btn-outline-primary navbar-btn rounded-circle">
    <a class="theme-switch" data-mode="light"><i class="fas fa-sun"></i></a>
    <a class="theme-switch" data-mode="dark"><i class="far fa-moon"></i></a>
    <a class="theme-switch" data-mode="auto"><i class="fas fa-adjust"></i></a>
</span>
      </div>
      
      <div class="navbar-end-item">
        <ul id="navbar-icon-links" class="navbar-nav" aria-label="Icon Links">
        <li class="nav-item">
          <a class="nav-link" href="https://github.com/datawhalechina/free-excel" rel="noopener" target="_blank" title="GitHub"><span><i class="fab fa-github-square"></i></span>
            <label class="sr-only">GitHub</label></a>
        </li>
      </ul>
      </div>
      
    </div>
  </div>
</div>
    </nav>
    

    <div class="bd-container container-xl">
      <div class="bd-container__inner row">
          

<!-- Only show if we have sidebars configured, else just a small margin  -->
<div class="bd-sidebar-primary col-12 col-md-3 bd-sidebar">
  <div class="sidebar-start-items"><form class="bd-search d-flex align-items-center" action="../search.html" method="get">
  <i class="icon fas fa-search"></i>
  <input type="search" class="form-control" name="q" id="search-input" placeholder="在这里搜索" aria-label="在这里搜索" autocomplete="off" >
</form><nav class="bd-links" id="bd-docs-nav" aria-label="Main navigation">
  <div class="bd-toc-item active">
    <ul class="current nav bd-sidenav">
 <li class="toctree-l1">
  <a class="reference internal" href="chap1.html">
   第一章 Excel与数据格式
  </a>
 </li>
 <li class="toctree-l1">
  <a class="reference internal" href="chap2.html">
   第二章 Excel的快捷操作
  </a>
 </li>
 <li class="toctree-l1">
  <a class="reference internal" href="chap3.html">
   第三章 Excel的表合并
  </a>
 </li>
 <li class="toctree-l1">
  <a class="reference internal" href="chap4.html">
   第四章 Excel函数-逻辑判断
  </a>
 </li>
 <li class="toctree-l1 current active">
  <a class="current reference internal" href="#">
   第五章 Excel函数-文本函数
  </a>
 </li>
 <li class="toctree-l1">
  <a class="reference internal" href="chap6.html">
   第六章 Excel函数-查找函数
  </a>
 </li>
 <li class="toctree-l1">
  <a class="reference internal" href="chap7.html">
   第七章 Excel函数-动态函数
  </a>
 </li>
 <li class="toctree-l1">
  <a class="reference internal" href="chap8.html">
   第八章Excel数据可视化
  </a>
 </li>
 <li class="toctree-l1">
  <a class="reference internal" href="chap9.html">
   第九章Excel数据透视
  </a>
 </li>
 <li class="toctree-l1">
  <a class="reference internal" href="chap10.html">
   第十章Excel看板
  </a>
 </li>
</ul>

  </div>
</nav>
  </div>
  <div class="sidebar-end-items">
  </div>
</div>


          


<div class="bd-sidebar-secondary d-none d-xl-block col-xl-2 bd-toc">
  
    
    <div class="toc-item">
      
<div class="tocsection onthispage mt-5 pt-1 pb-3">
    <i class="fas fa-list"></i> On this page
</div>

<nav id="bd-toc-nav">
    <ul class="visible nav section-nav flex-column">
 <li class="toc-h2 nav-item toc-entry">
  <a class="reference internal nav-link" href="#text">
   1.Text函数
  </a>
  <ul class="nav section-nav flex-column">
   <li class="toc-h3 nav-item toc-entry">
    <a class="reference internal nav-link" href="#id1">
     案例1
    </a>
   </li>
   <li class="toc-h3 nav-item toc-entry">
    <a class="reference internal nav-link" href="#id2">
     案例2
    </a>
   </li>
   <li class="toc-h3 nav-item toc-entry">
    <a class="reference internal nav-link" href="#id3">
     案例3
    </a>
   </li>
  </ul>
 </li>
 <li class="toc-h2 nav-item toc-entry">
  <a class="reference internal nav-link" href="#mid">
   2.mid函数
  </a>
 </li>
 <li class="toc-h2 nav-item toc-entry">
  <a class="reference internal nav-link" href="#replace">
   3.replace函数
  </a>
 </li>
 <li class="toc-h2 nav-item toc-entry">
  <a class="reference internal nav-link" href="#id4">
   练习
  </a>
 </li>
</ul>

</nav>
    </div>
    
    <div class="toc-item">
      
    </div>
    
  
</div>


          
          
          <div class="bd-content col-12 col-md-9 col-xl-7">
              
              <article class="bd-article" role="main">
                
  <div class="section" id="excel">
<h1>第五章 Excel函数-文本函数<a class="headerlink" href="#excel" title="Permalink to this heading">#</a></h1>
<div class="section" id="text">
<h2>1.Text函数<a class="headerlink" href="#text" title="Permalink to this heading">#</a></h2>
<p>Text函数可以将数值转换为指定格式的文本，其语法格式为TEXT(value,format_text)</p>
<p>【TEXT函数】=TEXT(值，自定义数字格式代码)</p>
<div class="section" id="id1">
<h3>案例1<a class="headerlink" href="#id1" title="Permalink to this heading">#</a></h3>
<p>打开<code class="docutils literal notranslate"><span class="pre">data/chap5/5.1.xlsx</span></code>，点击【案例1】，将客户的消费日期和消费金额转成大写</p>
<p>针对遇到的问题，那么在D2单元格中输入</p>
<p><strong>=TEXT(C2,”[DBNUM2]”)</strong> —-&gt; <strong>注意，这里的逗号要使用英文的逗号</strong></p>
<p>在E2单元格中输入</p>
<p><strong>=TEXT(A2,”[DBNUM1]yyyy年m月d日”)</strong></p>
<p>DBNUM1和DBNUM2为2种常见的中文格式，一般金额用DBNUM2，日期用DBNUM1</p>
<div class="figure align-default">
<img alt="" src="../_images/5.1.gif" />
</div>
</div>
<div class="section" id="id2">
<h3>案例2<a class="headerlink" href="#id2" title="Permalink to this heading">#</a></h3>
<p>打开<code class="docutils literal notranslate"><span class="pre">data/chap5/5.1.xlsx</span></code>，点击【案例2】，将客户的消费日期转换为周次，即星期几</p>
<p>针对遇到的问题，那么在D2单元格中输入</p>
<p><strong>=TEXT(A2,”aaaa”)</strong></p>
<div class="figure align-default">
<img alt="" src="../_images/5.2.gif" />
</div>
</div>
<div class="section" id="id3">
<h3>案例3<a class="headerlink" href="#id3" title="Permalink to this heading">#</a></h3>
<p>打开<code class="docutils literal notranslate"><span class="pre">data/chap5/5.1.xlsx</span></code>，点击【案例3】，取客户消费的年、月、日</p>
<p>针对遇到的问题，那么在D2单元格中输入</p>
<p><strong>=TEXT(A2,”yyyy”)</strong> 或者 <strong>=TEXT(A2,”e”)</strong></p>
<p>在E2单元格中输入</p>
<p><strong>=TEXT(A2,”m”)</strong> 或者 <strong>=TEXT(A2,”mm”)</strong> 注意.这2种格式是有区别的</p>
<p>在F2单元格中输入</p>
<p><strong>=TEXT(A2,”d”)</strong> 或者 <strong>=TEXT(A2,”dd”)</strong></p>
<div class="figure align-default">
<img alt="" src="../_images/5.3.gif" />
</div>
</div>
</div>
<div class="section" id="mid">
<h2>2.mid函数<a class="headerlink" href="#mid" title="Permalink to this heading">#</a></h2>
<p>打开<code class="docutils literal notranslate"><span class="pre">data/chap5/5.2.xlsx</span></code>，点击【案例1】，提取身份证中的生日，并转换成2022年12月4日这种格式</p>
<p>面对这个问题，可以使用mid函数提取生日</p>
<p>【MID函数】=MID(text,start<em>num,num</em>chars)</p>
<p>test:为要提取的文本字符串</p>
<p>start_num:为文本中要提取的第一个字符串的位置</p>
<p>num_chars为提取字符串的长度</p>
<p>因此可以在B2中输入 因为生日是8位数字，所以最后一个参数填8</p>
<p><strong>=MID(A2,7,8)</strong></p>
<p>在C2中输入格式化的生日</p>
<p><strong>=TEXT(MID(A2,7,8),”0000年00月00日”)</strong></p>
<p>问题：这里TEXT函数格式为什么没有使用yyyy年mm月dd日 这种格式？</p>
<p>因为MID(A2,7,8)提取出来的是文本，不是日期，因此Excel无法识别日期的年月，所以用数字格式进行代替</p>
<div class="figure align-default">
<img alt="" src="../_images/5.4.gif" />
</div>
<p>文本提取中相似的函数有LEFT，RIGHT</p>
<p>LEFT函数，以字符串左侧为起始位置，返回指定数量的字符</p>
<p>【LEFT函数】=MID(text,,num_chars)</p>
<blockquote>
<div><p>text:要提取的字符串或单元格引用；
num_chars:要提取的字符数量</p>
</div></blockquote>
<p>RIGHT函数，从字符串右侧首字符开始，从右向左提取指定的字符，其功能和LEFT函数完全一样，只是方向不同</p>
<p>【RIGHT函数】=MID(text,num_chars)</p>
<blockquote>
<div><p>text:要提取的字符串或单元格引用；
num_chars:要提取的字符数量</p>
</div></blockquote>
</div>
<div class="section" id="replace">
<h2>3.replace函数<a class="headerlink" href="#replace" title="Permalink to this heading">#</a></h2>
<p>打开<code class="docutils literal notranslate"><span class="pre">data/chap5/5.2.xlsx</span></code>，点击【案例2】，现在需要将Excel表格打印，为了不泄露客户电话号码，需要将电话后5位进行屏蔽</p>
<p>REPLACEI函数作用：把一个文本字符串，人为指定一个位置，用定个数新字符进行替换。</p>
<p>【REPLACEI函数】=REPLACEI(old<em>text,start</em>num,num<em>chars,new</em>text)</p>
<p>old_text:需要替换的文本</p>
<p>start_num:需要替换文本的开始位置</p>
<p>num_chars:替换文本的长度</p>
<p>new_text:替换内容</p>
<p>因此可以在B2单元格中输入</p>
<p><strong>=REPLACE(A2,11,5,”#####”)</strong></p>
<div class="figure align-default">
<img alt="" src="../_images/5.5.gif" />
</div>
</div>
<div class="section" id="id4">
<h2>练习<a class="headerlink" href="#id4" title="Permalink to this heading">#</a></h2>
<p>1.完成<code class="docutils literal notranslate"><span class="pre">data/chap5/5.1.xlsx</span></code>工作簿中的【案例1-3】</p>
<p>2.完成<code class="docutils literal notranslate"><span class="pre">data/chap5/5.2.xlsx</span></code>工作簿中的【案例1】中身份证后6位加密</p>
</div>
</div>


              </article>
              

              
          </div>
          
      </div>
    </div>

  
  
  <!-- Scripts loaded after <body> so the DOM is not blocked -->
  <script src="../_static/scripts/pydata-sphinx-theme.js?digest=92025949c220c2e29695"></script>

<footer class="bd-footer"><div class="bd-footer__inner container">
  
  <div class="footer-item">
    <p class="copyright">
    &copy; Copyright 2022, Datawhale, 牧小熊.<br>
</p>
  </div>
  
  <div class="footer-item">
    <p class="sphinx-version">
Created using <a href="http://sphinx-doc.org/">Sphinx</a> 5.3.0.<br>
</p>
  </div>
  
</div>
</footer>
  </body>
</html>